package com.bistu.openlab.uofspreadsheet.xmlparse;

import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.bistu.openlab.uofspreadsheet.model.DefaultHeightWidth;
import com.bistu.openlab.uofspreadsheet.util.TypeConvertor;
import com.bistu.openlab.uofspreadsheet.util.XmlDomHelper;

/*
 *@author xiaoguang.gao@oracle.com
 *@version 2013-5-9 
 */
public class DefaultHeightWidthParse implements IXmlParse<DefaultHeightWidth>{
	private static DefaultHeightWidthParse parse = new DefaultHeightWidthParse();
	private DefaultHeightWidthParse(){}
	/**
	 * 
	 * @return
	 */
	public static DefaultHeightWidthParse getInstance(){
		return parse;
	}

	@Override
	public DefaultHeightWidth readFromElement(Element root) {
		DefaultHeightWidth hw = null;
		if(root!=null){
			hw = new DefaultHeightWidth();
			double height = TypeConvertor.GetDouble(XmlDomHelper.GetAttributeValue(root, "缺省行高_E7EA"));
			hw.setHeight(height);
			double width = TypeConvertor.GetDouble(XmlDomHelper.GetAttributeValue(root, "缺省列宽_E7EB"));
			hw.setWidth(width);
		}
		return hw;
	}

	@Override
	public Element writeToElement(DefaultHeightWidth obj) {
		Element root = null;
		if(obj==null)
			obj = new DefaultHeightWidth();
		root = DocumentHelper.createElement("表:缺省行高列宽_E7E9");
		root.addAttribute("缺省行高_E7EA", obj.getHeight()+"");
		root.addAttribute("缺省列宽_E7EB", obj.getWidth()+"");
		return root;
	}

}
